import { DataMgr } from "../manager/DataMgr";
import { PlayerMgr } from "../manager/PlayerMgr";

export class GameDef {
    public static _instance: GameDef;
    private constructor() { }
    public static get instance(): GameDef {
        if (!GameDef._instance) {
            GameDef._instance = new GameDef();
        }
        return GameDef._instance;
    }
    /**训练营 基础分数 1-初级 2-中级 3-高级 0-训练营 */
    public readonly baseScore: number[] = [3000, 6000, 9000, 1500];

    /**训练营 最低分数  0-初级 1-中级 2-高级 3-基础 */
    public readonly baseLowestScore: number[] = [100, 300, 300, 100];

    /**连击倍数分母 */
    public readonly comboMultiple: number = 4;
    /**积分加成卡倍数 */
    public readonly cardMultiplePoints: number = 2;
    /**得分加成卡倍数 */
    public readonly cardMultipleScore: number = 1.5;
    /**连击时间 秒*/
    public readonly comboTime: number = 3;//s 
    /**消除时间 */
    public readonly clearTime: number = 10;//s


    /**当前关卡总分数 */
    public currLevelTotalScore: number = 0;
    /**当前关卡总积分 */
    public currLevelTotalPoints: number = 0;


    /**累计连击数 */
    public comboCount: number = -1;

    private _scoreRanges: { integral: number, scores: number[], isCurrLvGet: boolean }[] = [];
    /**本局通关时间 */
    public currGameTime: number = 0;
    /**本局积分 */
    public currGameScore: number = 0;
    /**当前游戏连胜 */
    private currGameWin: number = 0;
    /**色块密度 */
    public CBlockRate: number = (0.6 + Math.random() * 0.31);
    /**相同颜色的数量 */
    public siamese: number[] = [3, 6, 9]
    /**相同颜色的数量 随机概率 */
    public siameseRandom: number = 0.1;
    public gameTypeName: string[] = ["青铜赛", "白银赛", "黄金赛", "训练赛", "钻石赛", "王者赛"];
    private _curLevel = 1;
    /**当前关卡 */
    public get curLevel(): number {
        return PlayerMgr.instance.userData.getLevel(0);
    }

    public _cityName: string = "广东省";
    public get cityName(): string {
        return this._cityName;
    }
    public set cityName(value: string) {
        this._cityName = value;
    }

    public _proCode: string = "440000";
    public get proCode(): string {
        return this._proCode;
    }
    public set proCode(value: string) {
        this._proCode = value;
    }

    public gameSkin: string = 'gameTextrue4';

    /**重置关切数据 */
    public reInit() {
        this.currLevelTotalScore = 0
        this.currLevelTotalPoints = 0;
        this.comboCount = -1;
        this.currGameTime = 0;
        this.currGameScore = 0;
        this._scoreRanges = [
            { integral: 5, scores: [25000, 26000, 27000, 25000], isCurrLvGet: false },
            { integral: 10, scores: [50000, 100000, 100000, 50000], isCurrLvGet: false },
            { integral: 20, scores: [100000, 170000, 170000, 100000], isCurrLvGet: false },
            { integral: 40, scores: [200000, 500000, 500000, 200000], isCurrLvGet: false },
            { integral: 80, scores: [500000, 1000000, 1000000, 500000], isCurrLvGet: false },
            { integral: 160, scores: [1000000, 1700000, 1700000, 1000000], isCurrLvGet: false },
            { integral: 320, scores: [1500000, 5000000, 5000000, 1500000], isCurrLvGet: false }
        ];
        for (let key in this.reportInfo) {
            this.reportInfo[key] = 0;
        }
    }

    public get scoreRanges(): { integral: number, scores: number[], isCurrLvGet: boolean }[] {
        return this._scoreRanges
    }

    public getScoreRanges(type: number): number[] {
        let arr = []
        for (let i = 0; i < this._scoreRanges.length; i++) {
            arr.push(this._scoreRanges[i].scores[type])
        }
        return arr;

    }
    //获取当前档位的积分数
    public getCurrLevelScore(type: number, score: number): number {
        let arr = this.getScoreRanges(type)
        for (let i = 0; i < arr.length; i++) {
            if (score < arr[i]) {
                return arr[i]
            }
        }
        return arr[arr.length - 1]
    }
    public getCurrLevelPoints(type: number, score: number): number {
        let arr = this.getScoreRanges(type)
        for (let i = 0; i < arr.length; i++) {
            if (score < arr[i]) {
                return this._scoreRanges[i].integral
            }
        }
        return this._scoreRanges[this._scoreRanges.length - 1].integral
    }

    getCurrGameWin(isWin: boolean) {
        if (!isWin) {
            this.currGameWin = 0
            return 0
        }
        this.currGameWin++
        if (PlayerMgr.instance.getUserData().getHisMaxWin() < this.currGameWin) {
            PlayerMgr.instance.getUserData().setHisMaxWin(this.currGameWin)
            return this.currGameWin
        } else {
            return PlayerMgr.instance.getUserData().getHisMaxWin()
        }
    }
    /**色块大小 */
    // public BlockSize = [84, 56, 42];
    public BlockSize = [72, 72, 72, 72, 72];
    /**地图大小 */
    // public MapSize = [[8, 14], [12, 20], [16, 26]]
    public MapSize = [[10, 11], [10, 13], [10, 15], [10, 11], [10, 15]]
    /**色块 */
    public BlockColor = [
        "#a30000", "#009b00", "#b86e00", "#a7a700", "#e60ae6", "#01a3a3", "#000cb9",
        "#f3de20", "#16bdf0", "#0b7ee9", "#8c27ff", "#ff475f", "#8d528f", "#627e18",
        "#5febcc", "#91f591", "#e2c064", "#e26464", "#6464e2", "#64e2e2", "#522b52",
    ]
    public clockBlockType = [
        [1, 2, 3, 4, 5, 6],
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],
    ]
    public maskBlockCount = 6;
    public maskColorType = 12;
    public getLevelData(gameType) {
        let level = PlayerMgr.instance.userData.getLevel(gameType)
        let levelData = DataMgr.getInstance().getLevelCof(level,/**gameType */)
        console.log("关卡数据", levelData);
        let levelArrs = [];
        let obstacles: { 1: number[], 2: number[] } = { 1: [levelData.maskType1 / 2], 2: [levelData.maskType2 / 2] }// [levelData.maskType1,levelData.maskType2];
        for (let k in levelData) {
            if (k.indexOf('color') != -1) {
                if (levelData[k] > 0) {
                    levelArrs.push({ value: Number(k.replace("color", "")), count: levelData[k] })
                }
            }
        }
        return { levelData: levelArrs, obstacles: obstacles,level:level,wh:[levelData.length,levelData.high] }
    }
    public isNewLevel = false;
    public reportInfo = {
        /**复活视频次数 */
        revivetime: 0,
        /**提示视频次数*/
        tip: 0,
        /**刷新视频次数 */
        refresh: 0,
        /**敲碎视频次数 */
        knock: 0,
        ad_video_times: 0,
        /**关卡进度 */
        levelPorgress: 0,
        max_combo: 0,
        /**游戏类型 */
        gameType: -1,
    }
    public newGuideLevelData: number[][] = [
        [1, 0, 0, 0, 2, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 2],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 3, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 4, 0, 0, 0, 0, 0, 0, 4],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 3, 0, 0, 0]
    ];
}